package leetcode;

public class Solution124 {
    int maxDepth =  Integer.MIN_VALUE;;
    public int maxPathSum(TreeNode root) {
        maxDepth(root);
        return maxDepth;
    }
    public int maxDepth(TreeNode root){
        if(root == null){
            return 0;
        }
        int left = Math.max(maxDepth(root.left),0);
        int right= Math.max(maxDepth(root.right),0);
        maxDepth = Math.max(root.val+left + right,maxDepth);
        return root.val+Math.max(left,right);
    }
}
